home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / doc / applet / overview / classes / good.000 < prev    next >
Encoding:
Text File  |  1996-02-26  |  2.2 KB  |  94 lines

  1. <!--NewPage-->
  2. <html>
  3. <head>
  4. <title>Good.java</title>
  5. </head>
  6. <body>
  7. <p>
  8. <hr size=4>
  9.  
  10. <h2>
  11.     Good.java
  12. </h2>
  13. <p>
  14. <blockquote>
  15.  
  16. <pre>
  17.  
  18. /*
  19.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  20.  *
  21.  * Permission to use, copy, modify, and distribute this software
  22.  * and its documentation for NON-COMMERCIAL purposes and without
  23.  * fee is hereby granted provided that this copyright notice
  24.  * appears in all copies. Please refer to the file "copyright.html"
  25.  * for further important copyright and licensing information.
  26.  *
  27.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  28.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  29.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  30.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  31.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  32.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  33.  */
  34. import browser.Applet;
  35. import awt.Graphics;
  36.  
  37. class Good extends Applet implements Runnable {
  38.  
  39.     static final int NUMLOOPS = 2000000;
  40.     int loop = 0;
  41.     boolean doneInitializing = false;
  42.     String message = null;
  43.     Thread loopThread = null;
  44.  
  45.     public void init() {
  46.     resize(500, 20);
  47.     }
  48.  
  49.     public void start() {
  50.     if (loopThread == null) {
  51.         loopThread = new Thread(this, "Good thread");
  52.         loopThread.start();
  53.     }
  54.     }
  55.  
  56.     public void stop() {
  57.     loopThread.stop();
  58.     loopThread = null;
  59.     }
  60.  
  61.     public void run() {
  62.     while (loop < NUMLOOPS) {
  63.         if ((++loop%50000)==0) {
  64.         message = "Good: Initialization loop #"
  65.               + loop + " of " + NUMLOOPS;
  66.         showStatus(message);
  67.         repaint();
  68.         }
  69.     }
  70.     doneInitializing = true;
  71.     repaint();
  72.     }
  73.  
  74.  
  75.     /* The paint() method can't be called until init() has exited. */
  76.     public void paint(Graphics g) {
  77.     g.clearRect(0, 0, width - 1, height - 1);
  78.     g.drawRect(0, 0, width - 1, height - 1);
  79.     if (message == null) 
  80.         g.drawString("Good: ", 5, 15);
  81.     else if (!doneInitializing) 
  82.         g.drawString(message, 5, 15);
  83.     else 
  84.         g.drawString("Good: Done initializing.", 5, 15);
  85.     }
  86. }
  87. </pre>
  88. </blockquote>
  89. <p>
  90. <hr size=4>
  91. <p>
  92. </body>
  93. </html>
  94.